package com.coffee.takeoutserver.controller;

import com.coffee.takeoutserver.bean.Seller;
import com.coffee.takeoutserver.util.ResponseInfo;
import com.coffee.takeoutserver.service.HomeService;
import com.coffee.takeoutserver.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class HomeController {

    @Autowired
    private HomeService homeService;

    @RequestMapping("home")
    @ResponseBody
    public String home() {
        List<Seller> sellerList = homeService.home();
        ResponseInfo res = new ResponseInfo();
        res.setCode("0");
        Map<String, String> map = new HashMap<>();
        map.put("nearbySellerList", JsonUtil.getGson().toJson(sellerList));
        map.put("otherSellerList", JsonUtil.getGson().toJson(sellerList));
        res.setData(JsonUtil.getGson().toJson(map));
        return JsonUtil.getGson().toJson(res);
    }
}
